<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>Linux 命令- tar | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>Linux 命令- tar</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Linux命令/">Linux命令</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;通过SSH访问服务器，难免会要用到压缩，解压缩，打包，解包等，这时候tar命令就是是必不可少的一个功能强大的工具。linux中最流行的tar是麻雀虽小，五脏俱全，功能强大。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;tar命令可以为linux的文件和目录创建档案。利用tar，可以为某一特定文件创建档案（备份文件），也可以在档案中改变文件，或者向档案中加入新的文件。tar最初被用来在磁带上创建档案，现在，用户可以在任何设备上创建档案。利用tar命令，可以把一大堆的文件和目录全部打包成一个文件，这对于备份文件或将几个文件组合成为一个文件以便于网络传输是非常有用的。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;首先要弄清两个概念：打包和压缩。打包是指将一大堆文件或目录变成一个总的文件；压缩则是将一个大的文件通过一些压缩算法变成一个小文件。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;为什么要区分这两个概念呢？这源于Linux中很多压缩程序只能针对一个文件进行压缩，这样当你想要压缩一大堆文件时，你得先将这一大堆文件先打成一个包（tar命令），然后再用压缩程序进行压缩（gzip bzip2命令）。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;linux下最常用的打包程序就是tar了，使用tar程序打出来的包我们常称为tar包，tar包文件的命令通常都是以.tar结尾的。生成tar包后，就可以用其它的程序来进行压缩。</p>
<h2 id="1-命令格式"><a href="#1-命令格式" class="headerlink" title="1.命令格式"></a>1.命令格式</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tar [必要参数] [选择参数] [文件]</div></pre></td></tr></table></figure>
<h2 id="2-命令功能"><a href="#2-命令功能" class="headerlink" title="2.命令功能"></a>2.命令功能</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;用来压缩和解压文件。tar 本身不具有压缩功能。它是调用压缩功能实现的。</p>
<h2 id="3-命令参数"><a href="#3-命令参数" class="headerlink" title="3.命令参数"></a>3.命令参数</h2><h3 id="必要参数"><a href="#必要参数" class="headerlink" title="必要参数"></a>必要参数</h3><ul>
<li>-A 新增压缩文件到已存在的压缩</li>
<li>-B 设置区块大小</li>
<li>-c 建立新的压缩文件</li>
<li>-d 记录文件的差别</li>
<li>-r 添加文件到已经压缩的文件</li>
<li>-u 添加改变了和现有的文件到已经存在的压缩文件</li>
<li>-x 从压缩的文件中提取文件</li>
<li>-t 显示压缩文件的内容</li>
<li>-z 支持gzip解压文件</li>
<li>-j 支持bzip2解压文件</li>
<li>-Z 支持compress解压文件</li>
<li>-v 显示操作过程</li>
<li>-l 文件系统边界设置</li>
<li>-k 保留原有文件不覆盖</li>
<li>-m 保留文件不被覆盖</li>
<li>-W 确认压缩文件的正确性</li>
</ul>
<h3 id="可选择参数"><a href="#可选择参数" class="headerlink" title="可选择参数"></a>可选择参数</h3><ul>
<li>-b 设置区块数目</li>
<li>-C 切换到指定目录</li>
<li>-f 指定压缩文件</li>
<li>–help 显示帮助信息</li>
<li>–version 显示版本信息</li>
</ul>
<h2 id="4-常见压缩、解压命令"><a href="#4-常见压缩、解压命令" class="headerlink" title="4.常见压缩、解压命令"></a>4.常见压缩、解压命令</h2><h3 id="tar"><a href="#tar" class="headerlink" title="tar"></a>tar</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解包</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tar xvf filname.tar</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;打包</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tar cvf filename.tar dirname</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;注意：tar 是打包，不是压缩！</p>
<h3 id="gz"><a href="#gz" class="headerlink" title=".gz"></a>.gz</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解压1</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">gunzip filename.gz</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解压2</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">gzip -d filename.gz</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;压缩</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">gzip filename.tar.gz</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解压</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tar zxvf filename.tar.gz</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;压缩</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tar zcvf filename.tar.gz dirname</div></pre></td></tr></table></figure>
<h3 id="bz2"><a href="#bz2" class="headerlink" title=".bz2"></a>.bz2</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解压1</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">bzip2 -d filename.bz2</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解压2</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">bunzip2 filename.bz2</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;压缩</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">bzip2 -z filename.tar.bz2</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解压</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tar jxvf filename.tar.bz2</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;压缩</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tar jcvf filename.tar.bz2 diename</div></pre></td></tr></table></figure>
<h3 id="Z"><a href="#Z" class="headerlink" title=".Z"></a>.Z</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解压</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">unconpress filename.Z</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;压缩</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">compress filename.tar.Z</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解压</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tar Zxvf filename.tar.Z</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;压缩</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tar Zcvf filename.tar.Z dirname</div></pre></td></tr></table></figure>
<h3 id="zip"><a href="#zip" class="headerlink" title=".zip"></a>.zip</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解压</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">unzip filename.zip</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;压缩</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">zip filename.zip dirname</div></pre></td></tr></table></figure>
<h3 id="rar"><a href="#rar" class="headerlink" title=".rar"></a>.rar</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解压</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">rar x filename.rar</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;压缩</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">rar a filename.rar dirname</div></pre></td></tr></table></figure>
<h2 id="5-使用实例"><a href="#5-使用实例" class="headerlink" title="5.使用实例"></a>5.使用实例</h2><h3 id="实例1：将文件全部打包成-tar-包"><a href="#实例1：将文件全部打包成-tar-包" class="headerlink" title="实例1：将文件全部打包成 tar 包"></a>实例1：将文件全部打包成 tar 包</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">tar -cvf log.tar log2012.log</div><div class="line">tar -zxvf log.tar.gz log2012.log</div><div class="line">tar -jcvf log.tar.bz2 log2012.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ls -al log2012.log</span></div><div class="line">---xrw-r-- 1 root root 302108 11-13 06:03 log2012.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># tar -cvf log.tar log2012.log </span></div><div class="line">log2012.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># tar -zcvf log.tar.gz log2012.log</span></div><div class="line">log2012.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># tar -jcvf log.tar.bz2 log2012.log </span></div><div class="line">log2012.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ls -al *.tar*</span></div><div class="line">-rw-r--r-- 1 root root 307200 11-29 17:54 log.tar</div><div class="line">-rw-r--r-- 1 root root   1413 11-29 17:55 log.tar.bz2</div><div class="line">-rw-r--r-- 1 root root   1413 11-29 17:54 log.tar.gz</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<ol>
<li>tar -cvf log.tar log2012.log    仅打包，不压缩！     </li>
<li>tar -zcvf log.tar.gz log2012.log   打包后，以 gzip 压缩     </li>
<li>tar -zcvf log.tar.bz2 log2012.log  打包后，以 bzip2 压缩     </li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在参数 f 之后的文件档名是自己去的，习惯上都用 .tar 来作为辨识。如果加 z 参数，则以 .tar.gz 或 .tgz 来代表 gzip 压缩过的 tar 包；如果加 j 参数，则以 .tar.bz2 来作为 tar 报名。</p>
<h3 id="实例2：查阅上述-tar-包内有哪些文件"><a href="#实例2：查阅上述-tar-包内有哪些文件" class="headerlink" title="实例2：查阅上述 tar 包内有哪些文件"></a>实例2：查阅上述 tar 包内有哪些文件</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tar -ztvf log.tar.gz</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># tar -ztvf log.tar.gz</span></div><div class="line">---xrw-r-- root/root    302108 2012-11-13 06:03:25 log2012.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;由于使用 gzip 压缩的 log.tar.gz，所以要查阅 log.tar.gz 包内的文件时，就要加上 z 这个参数</p>
<h3 id="实例3：将-tar-包解压缩"><a href="#实例3：将-tar-包解压缩" class="headerlink" title="实例3：将 tar 包解压缩"></a>实例3：将 tar 包解压缩</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tar -zxvf /opt/soft/<span class="built_in">test</span>/log.tar.gz</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">[root@localhost test3]<span class="comment"># ll</span></div><div class="line">总计 0[root@localhost test3]<span class="comment"># tar -zxvf /opt/soft/test/log.tar.gz</span></div><div class="line">log2012.log</div><div class="line">[root@localhost test3]<span class="comment"># ls</span></div><div class="line">log2012.log</div><div class="line">[root@localhost test3]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在预设的情况下，可以将压缩当在任何地方解压</p>
<h3 id="实例4：只将-tar-内的部分文件解压出来"><a href="#实例4：只将-tar-内的部分文件解压出来" class="headerlink" title="实例4：只将 /tar 内的部分文件解压出来"></a>实例4：只将 /tar 内的部分文件解压出来</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tar -zxvf /opt/soft/<span class="built_in">test</span>/log30.tar.gz log2013.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># tar -zcvf log30.tar.gz log2012.log log2013.log </span></div><div class="line">log2012.log</div><div class="line">log2013.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ls -al log30.tar.gz </span></div><div class="line">-rw-r--r-- 1 root root 1512 11-30 08:19 log30.tar.gz</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># tar -zxvf log30.tar.gz log2013.log</span></div><div class="line">log2013.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">-rw-r--r-- 1 root root   1512 11-30 08:19 log30.tar.gz</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test3</span></div><div class="line">[root@localhost test3]<span class="comment"># tar -zxvf /opt/soft/test/log30.tar.gz log2013.log</span></div><div class="line">log2013.log</div><div class="line">[root@localhost test3]<span class="comment"># ll</span></div><div class="line">总计 4</div><div class="line">-rw-r--r-- 1 root root 61 11-13 06:03 log2013.log</div><div class="line">[root@localhost test3]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;可以投过 tar -ztvf 来查阅 tar 包内的文件名称，如果单只要一个文件，就可透过这个方式来解压部分文件！</p>
<h2 id="实例5：文件备份下来，并且保存其权限"><a href="#实例5：文件备份下来，并且保存其权限" class="headerlink" title="实例5：文件备份下来，并且保存其权限"></a>实例5：文件备份下来，并且保存其权限</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tar -zcvpf log31.tar.gz log2014.log log2015.log lo2016.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">总计 0</div><div class="line">-rw-r--r-- 1 root root      0 11-13 06:03 log2014.log</div><div class="line">-rw-r--r-- 1 root root      0 11-13 06:06 log2015.log</div><div class="line">-rw-r--r-- 1 root root      0 11-16 14:41 log2016.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># tar -zcvpf log31.tar.gz log2014.log log2015.log log2016.log </span></div><div class="line">log2014.log</div><div class="line">log2015.log</div><div class="line">log2016.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test6</span></div><div class="line">[root@localhost test6]<span class="comment"># ll</span></div><div class="line">[root@localhost test6]<span class="comment"># tar -zxvpf /opt/soft/test/log31.tar.gz </span></div><div class="line">log2014.log</div><div class="line">log2015.log</div><div class="line">log2016.log</div><div class="line">[root@localhost test6]<span class="comment"># ll</span></div><div class="line">总计 0</div><div class="line">-rw-r--r-- 1 root root 0 11-13 06:03 log2014.log</div><div class="line">-rw-r--r-- 1 root root 0 11-13 06:06 log2015.log</div><div class="line">-rw-r--r-- 1 root root 0 11-16 14:41 log2016.log</div><div class="line">[root@localhost test6]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这个 -p 的属性是很重要的，尤其是要保留原文本文件的属性时</p>
<h3 id="实例6：在文件夹当中，比某个日期新的文件才备份"><a href="#实例6：在文件夹当中，比某个日期新的文件才备份" class="headerlink" title="实例6：在文件夹当中，比某个日期新的文件才备份"></a>实例6：在文件夹当中，比某个日期新的文件才备份</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tar -N <span class="string">"2012/11/13"</span> -zcvf log17.tar.gz <span class="built_in">test</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">[root@localhost soft]<span class="comment"># tar -N "2012/11/13" -zcvf log17.tar.gz test</span></div><div class="line">tar: Treating date `2012/11/13<span class="string">' as 2012-11-13 00:00:00 + 0 nanoseconds</span></div><div class="line"><span class="string">test/test/log31.tar.gz</span></div><div class="line"><span class="string">test/log2014.log</span></div><div class="line"><span class="string">test/linklog.log</span></div><div class="line"><span class="string">test/log2015.log</span></div><div class="line"><span class="string">test/log2013.log</span></div><div class="line"><span class="string">test/log2012.log</span></div><div class="line"><span class="string">test/log2017.log</span></div><div class="line"><span class="string">test/log2016.log</span></div><div class="line"><span class="string">test/log30.tar.gz</span></div><div class="line"><span class="string">test/log.tar</span></div><div class="line"><span class="string">test/log.tar.bz2</span></div><div class="line"><span class="string">test/log.tar.gz</span></div></pre></td></tr></table></figure>
<h3 id="实例7：备份文件夹内容是排除部分文件"><a href="#实例7：备份文件夹内容是排除部分文件" class="headerlink" title="实例7：备份文件夹内容是排除部分文件"></a>实例7：备份文件夹内容是排除部分文件</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tar --exclide scf/service -zcvf scf.tar/gz scf/*</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># tree scf</span></div><div class="line">scf</div><div class="line">|-- bin</div><div class="line">|-- doc</div><div class="line">|-- lib</div><div class="line">`-- service</div><div class="line">   	 `-- deploy</div><div class="line">       	 	|-- info</div><div class="line">       	 	`-- product</div><div class="line">7 directories, 0 files</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># tar --exclude scf/service -zcvf scf.tar.gz scf/* </span></div><div class="line">scf/bin/</div><div class="line">scf/doc/</div><div class="line">scf/lib/</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment">#</span></div></pre></td></tr></table></figure>
	

	
		<span class="different-posts"><a href="/2017/10/12/2. Linux 命令/28. Linux 命令- tar/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
